package com.heima.article.controller.v1;

import com.heima.article.constants.ArticleConstants;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 霍森彪
 * @date 2022/7/14 11:22
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArtcleController {

    @Autowired
    private ApArticleService apArticleService;

    //文章服务,加载首页
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        //return apArticleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return apArticleService.load2(dto, true);
    }

    //加载更多
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list =  apArticleService.load(dto,ArticleConstants.LOADTYPE_LOAD_MORE);
        return ResponseResult.okResult(list);

    }

    //加载更新
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto){
        List<ApArticle> list = apArticleService.load(dto,ArticleConstants.LOADTYPE_LOAD_NEW);
        return ResponseResult.okResult(list);
    }

    /**
     * 详情页数据回显
     * @param dto
     * @return
     */
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticleBehavior(dto);
    }
}
